package com.zhanghe.im.decoder;

import com.zhanghe.im.protocol.command.Packet;
import com.zhanghe.im.protocol.command.PacketCodeC;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

/**
 * PacketDecoder
 *
 * @author Clevo
 * @date 2018/10/23
 */
public class PacketDecoder extends ByteToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        Packet packet =  PacketCodeC.INSTANCE.decode(byteBuf);
        System.out.println("接收到消息:"+packet.getClass());
        list.add(packet);
    }

}
